unit uERP_DAO;

interface

uses uERP_DAO_Usuario, uERP_DAO_Contador;

type
  TDAO = class

    {$REGION '<< Private >>'}

      private

        {$REGION '<< Atributes >>'}

          class var _Instance: TDAO;

          var _DAOUsuario: TDAOUsuario;
          var _DAOContador: TDAOContador;

        {$ENDREGION}

    {$ENDREGION}

    {$REGION '<< Public >>'}

      public

        {$REGION '<< Methods >>'}

          class function GetInstance(): TDAO;
          class procedure FreeInstance();

          function GetDAOUsuario(): TDAOUsuario;
          function GetDAOContador(): TDAOContador;

        {$ENDREGION}

    {$ENDREGION}

  end;

implementation

uses
  SysUtils;

{$REGION '<< TDAO >>'}

class procedure TDAO.FreeInstance;
begin
  FreeAndNil(_Instance);
end;

class function TDAO.GetInstance: TDAO;
begin
  if not Assigned(_Instance)
    then _Instance := inherited Create as Self;
  Result := _Instance;
end;

function TDAO.GetDAOContador: TDAOContador;
begin
  if not Assigned(_DAOContador)
    then _DAOContador := TDAOContador.Create();
  Result := _DAOContador;
end;

function TDAO.GetDAOUsuario: TDAOUsuario;
begin
  if not Assigned(_DAOUsuario)
    then _DAOUsuario := TDAOUsuario.Create();
  Result := _DAOUsuario;
end;

{$ENDREGION}

initialization

finalization
  TDAO.GetInstance().FreeInstance();

end.
